<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */

class Home_model extends CI_Model
{

    public function getProductByCatId($id, $langCode)
    {
        $this->db->select("item.id, name_$langCode as 'name', image_src, content_$langCode as 'content', summary_$langCode as 'summary'");
        $this->db->from('item');
        $this->db->where('product_id',$id);
        $r = $this->db->get();
        $return = $r->result_array();
        $r->free_result();
        return $return;
    }
    
    public function getCatInfo($id, $langCode)
    {
        $this->db->select("name_$langCode as 'name', parent_id");
        $this->db->from('product');
        $this->db->where('id', $id);
        $r = $this->db->get();
        $return = $r->result_array();
        $r->free_result();
        return $return;
    }
    
    public function getNumProByCatId($id, $langCode)
    {
        $this->db->select('*');
        $this->db->from('item');
        $this->db->where('product_id', $id);
        $r = $this->db->get();
        return $r->num_rows;
    }
    
    public function search($keywords, $langCode)
    {
        $this->db->select("item.id, name_$langCode as 'name', image_src, content_$langCode as 'content', summary_$langCode as 'summary'");
        $this->db->from('item');
        $this->db->like("name_$langCode", $keywords, 'both');
        $this->db->or_like("content_$langCode", $keywords, 'both');
        $this->db->or_like("summary_$langCode", $keywords, 'both');
        $rs = $this->db->get();
        $return = $rs->result_array();
        $rs->free_result();
        return $return;
    }

}

?>
